/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package app.actions;

import app.negocio.GestionLibreria;
import app.negocio.ItfzGestionLibreria;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Johann
 */
public class EliminarLibroAction extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        String forward = "ko";
        
        //Recuperamos el parámetros pasado por url
        if(request.getParameter("id") != null){
            ItfzGestionLibreria libreria = new GestionLibreria();
            if(libreria.eliminarLibro(Integer.parseInt(request.getParameter("id")))){
                request.setAttribute("libroEliminadoOK", "Libro eliminado correctamente");
                forward = "ok";
            } else {
                request.setAttribute("libroEliminadoKO", "No se ha podido eliminar el libro.");
            }
        }
        //Redirigir a la vista elegida. Desde la configuración se vuelve a llamar
        // a consultar todos los libros, para refrescar los datos.
        return mapping.findForward(forward);
    }
    
    
}
